<?php

namespace App\Models\Order;

use App\Models\Video;
use Illuminate\Database\Eloquent\Model;

class Item extends Model
{

    protected $table = 'order_items';

    protected $fillable = ['order_id', 'author_id', 'item_total', 'video_id'];

    protected $appends = [
        'item_total'
    ];

    public function setItemTotalAttribute($value)
    {
        $this->attributes['item_total'] = intval(($value * 100));
    }

    public function getItemTotalAttribute($value)
    {
        return round($this->attributes['item_total'] / 100, 2);
    }

    public function video()
    {
        return $this->hasOne(Video::class, 'id', 'video_id');
    }
}